package com.lnking.lnkingplace.service.impl;


import com.lnking.lnkingplace.mapper.CultureEnterpriseMapper;
import com.lnking.lnkingplace.model.dto.cultureEnterprise.CultureEnterpriseImport;
import com.lnking.lnkingplace.model.dto.isolation.leadership.LeadershipImport;
import com.lnking.lnkingplace.model.entity.CultureEnterprise;
import com.lnking.lnkingplace.model.entity.Exhibition;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureAddRequest;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureUpdateRequest;
import com.lnking.lnkingplace.service.ICultureEnterpriseService;
import com.lnking.starter.export.utils.ImportOption;
import com.lnking.starter.export.utils.ImportUtils;
import com.lnking.starter.mybatis.service.impl.CustomServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 文创企业表 服务实现类
 * </p>
 *
 * @author zhangqt
 * @since 2022-10-05
 */
@Service
public class CultureEnterpriseServiceImpl extends CustomServiceImpl<CultureEnterpriseMapper, CultureEnterprise> implements ICultureEnterpriseService {

    @Override
    public void add(CultureAddRequest params) {
        CultureEnterprise info = new CultureEnterprise();
        BeanUtils.copyProperties(params,info);
        info.setCreateTime(LocalDateTime.now());
        this.baseMapper.insert(info);
    }



    @Override
    public void update(CultureUpdateRequest params) {
        CultureEnterprise info = new CultureEnterprise();
        BeanUtils.copyProperties(params,info);
        this.baseMapper.updateById(info);
    }

    @Override
    public void importExcel(MultipartFile file) throws Exception {
        ImportOption option = new ImportOption.Builder().build();
        List<CultureEnterpriseImport> result =  ImportUtils.importExcel(file, CultureEnterpriseImport.class,option);
        for (CultureEnterpriseImport cultureEnterpriseImport : result) {
            if(StringUtils.isNotBlank(cultureEnterpriseImport.getEnterpriseName())){
                CultureEnterprise info = new CultureEnterprise();
                BeanUtils.copyProperties(cultureEnterpriseImport,info);
                info.setCreateTime(LocalDateTime.now());
                if(StringUtils.isNotBlank(cultureEnterpriseImport.getYear())){
                    info.setYear(Integer.valueOf(cultureEnterpriseImport.getYear()));
                }
                if(StringUtils.isNotBlank(cultureEnterpriseImport.getGrowSeason())){
                    info.setGrowSeason(Float.valueOf(cultureEnterpriseImport.getGrowSeason()));
                }
                this.baseMapper.insert(info);
            }

        }
    }
}
